/*
 *  test_process.c
 *
 *  Created on: May 15, 2011
 *  Author: Sergiy Kulyk
 */


#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>
#include "../src/process.h"



/* The suite initialization function.
 * Opens the temporary file used by the tests.
 * Returns zero on success, non-zero otherwise.
 */
int init_suite1(void)
{
    /* Here we put code that will run before
     * the entire test suit runs. */
    return 0;
}


/* The suite cleanup function.
 * Closes the temporary file used by the tests.
 * Returns zero on success, non-zero otherwise.
 */
int clean_suite1(void)
{
    /* Here we put code that will run after
     * the entire test suit runs. */
    return 0;
}


/****** Test functions ********/

void test_new_request_type(void) {

    s_request_type_t * rt = s_new_request_type(10, IO);
    if (rt) {
        CU_ASSERT(rt->step == 10);
        CU_ASSERT(rt->type == IO);
    }
}

void test_new_process(void) {

    s_request_type_t req_array[] = {
        *s_new_request_type(10, IO),
        *s_new_request_type(20, IO),
        *s_new_request_type(30, IO)
    };

    s_process_t * p = s_new_process(100, 3, req_array, CALCULATING);
    CU_ASSERT(p->num_steps == 100);
    CU_ASSERT(p->num_requests == 3);
    CU_ASSERT(p->process_type == CALCULATING);

    int i;
    for (i = 0; i < 3; i++) {
        CU_ASSERT(p->req_type[i].step == i * 10 + 10);
    }
}

/******  End Test functions ********/

int main(void) {

    CU_pSuite pSuite = NULL;

    /* initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* add a suite to the registry */
    pSuite = CU_add_suite("Suite_1", init_suite1, clean_suite1);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* add the tests to the suite */
    if ((NULL == CU_add_test(pSuite, "test of s_new_request_type()", test_new_request_type)) ||
            (NULL == CU_add_test(pSuite, "test of new_process()", test_new_process)))
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Run all tests using the CUnit Basic interface */
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}

